var isIe=(document.all)?true:false;

function includeMyAlert(){
    var myAlert = $("<span id='myAlertMask'></span>" +
    "<div id='myAlertDialog'>" +
        "<div class='title'>" +
            "<img src = '"+domain+"/views/images/myalert/close.gif' alt='点击可以关闭'/>" +
        "</div>" +
        "<div class='myAlertContent'>" +
            "<table style='width:100%' border='0' cellpadding='0' cellspacing='0'>" +
                "<tr>" +
                    "<td valign='top'>" +
                        "<img src='"+domain+"/views/images/myalert/delete.jpg' alt=''/>" +
                    "</td>" +
                    "<td>" +
                        "<div>&nbsp;</div>" +
                    "</td>" +
                "</tr>" +
            "</table>" +
        "</div>" +
        "<div class='bottom'>" +
            "<input type='button' value='确定' class='btn'/>" +
        "</div>" +
    "</div>"
    );

    $("body").append(myAlert);

    var myConfirm = $("<div id='myConfirmDialog'>" +
        "<div class='title'>" +
            "<img src = '"+domain+"/views/images/myalert/close.gif' alt='点击可以关闭'/>" +
        "</div>" +
        "<div class='myConfirmContent'>" +
            "<table style='width:100%' border='0' cellpadding='0' cellspacing='0'>" +
                "<tr>" +
                    "<td valign='top'>" +
                        "<img src='"+domain+"/views/images/myalert/help.gif' alt=''/>" +
                    "</td>" +
                    "<td>" +
                        "<div class='myConfirmText'></div>" +
                    "</td>" +
                "</tr>" +
            "</table>" +
        "</div>" +
        "<div class='bottom'>" +
            "<input id='confirmButton' type='button' value='确定' class='btn'/>" +
            "<input id='cancelButton' type='button' value='取消' class='btn'/>" +
        "</div>" +
    "</div>"
    );

    $("body").append(myConfirm);

    $("body #myAlertDialog").css({"border": "solid 2px #FFFFFF"});
    $("body #myConfirmDialog").css({"border": "solid 2px #FFFFFF"});

    $(window).resize(function(){
        if(!$("#myAlertDialog").is(":visible")){
            return;
        }else{
            myAlertShowDialog();
        }
        if(!$("#myConfirmDialog").is(":visible")){
            return;
        }else{
            myAlertShowConfirmDialog();
        }

    });
    $("#myAlertDialog .title img").click(function(){
        if($("#myAlertDialog").is(":visible")){
           $("#myAlertDialog").hide();
        }
        $("#myAlertMask").hide();
    })
    $("#myConfirmDialog .title img").click(function(){
        if($("#myConfirmDialog").is(":visible")){
            $("#myConfirmDialog").hide();
        }
        $("#myAlertMask").hide();
    })
    $("#myAlertDialog .bottom .btn").click(function(){
        $("#myAlertDialog").hide();
        $("#myAlertMask").hide();
    })
    $("#cancelButton").click(function(){
        $("#myConfirmDialog").hide();
        $("#myAlertMask").hide();
        //setRightDivWidth();
    })
}

function myAlertShowDialog(){
    var objW = $(window);
    var objC = $("#myAlertDialog");
    var brsW = objW.width();
    var brsH = objW.height();
    var sclL = objW.scrollLeft();
    var sclT = objW.scrollTop();
    var curW = objC.width();
    var curH = objC.height();
    $("#myAlertMask").height(brsH+curH+sclT);

    var left = sclL + (brsW - curW) / 2;
    var top;
    if(brsH < curH){
        top = 10;
    }else{
        top = sclT + (brsH - curH) / 2;
    }
    objC.css({"left":left, "top":top});
}

function myAlertShowConfirmDialog(){
    var objW = $(window);
    var objC = $("#myConfirmDialog");
    var brsW = objW.width();
    var brsH = objW.height();
    var sclL = objW.scrollLeft();
    var sclT = objW.scrollTop();
    var curW = objC.width();
    var curH = objC.height();
    $("#myAlertMask").height(brsH+curH+sclT);

    var left = sclL + (brsW - curW) / 2;
    var top;
    if(brsH < curH){
        top = 10;
    }else{
        top = sclT + (brsH - curH) / 2;
    }
    objC.css({"left":left, "top":top});
}


function myAlert(data){
    $("#myAlertMask").show();
    $("#myAlertDialog .myAlertContent div").html(data);
    myAlertShowDialog();
    $("#myAlertDialog").show();
}

function myAlertWithCallback(data,callback){
    $("#myAlertMask").show();
    $("#myAlertDialog .myAlertContent div").html(data);
    myAlertShowDialog();
    $("#myAlertDialog").show();
    $("#myAlertDialog .bottom .btn").unbind();
    $("#myAlertDialog .bottom .btn").click(function(){
        $("#myAlertDialog").hide();
        $("#myAlertMask").hide();
        if(callback){
        	callback();
        }
    })
}

function myConfirm(data, callback){
    $("#myAlertMask").show();
    $("#myConfirmDialog .myConfirmContent .myConfirmText").html(data);
    $("#confirmButton").unbind();
    $("#confirmButton").click(function(){
    	$("#myConfirmDialog").hide();
        $("#myAlertMask").hide();
    	callback();
    });
    myAlertShowConfirmDialog();
    $("#myConfirmDialog").show();
}